4 // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
6 // The use and distribution terms for this software are contained in the file
7 // named license.txt, which can be found in the root of this distribution.
8 // By using this software in any fashion, you are agreeing to be bound by the
9 // terms of this license.
11 // You must not remove this notice, or any other, from this software.
16 namespace Microsoft
.JScript
{
18 using Microsoft
.JScript
.Vsa
;
20 using System
.Reflection
;
21 using System
.Reflection
.Emit
;
23 public sealed class Typeof
: UnaryOp
{
24 internal Typeof(Context context
, AST operand
)
25 : base(context
, operand
) {
28 internal override Object
Evaluate(){
30 return JScriptTypeof(this.operand
.Evaluate(), VsaEngine
.executeForJSEE
);
31 }catch(JScriptException e
){
32 if ((e
.Number
& 0xFFFF) == (int)JSError
.UndefinedIdentifier
)
38 internal override IReflect
InferType(JSField inference_target
){
42 public static String
JScriptTypeof(Object
value){
43 return JScriptTypeof(value, false);
46 internal static String
JScriptTypeof(Object
value, bool checkForDebuggerObject
){
47 switch (Convert
.GetTypeCode(value)){
53 if (value is Missing
|| value is System
.Reflection
.Missing
) return "undefined";
54 return value is ScriptFunction
? "function" : "object";
55 case TypeCode
.Boolean
:
70 case TypeCode
.Decimal
:
72 case TypeCode
.DateTime
:
78 internal override void TranslateToIL(ILGenerator il
, Type rtype
){
79 if (this.operand
is Binding
)
80 //Make sure that no exception is thrown if the operand is an undefined identifier
81 ((Binding
)this.operand
).TranslateToIL(il
, Typeob
.Object
, true);
83 this.operand
.TranslateToIL(il
, Typeob
.Object
);
84 il
.Emit(OpCodes
.Call
, CompilerGlobals
.jScriptTypeofMethod
);
85 Convert
.Emit(this, il
, Typeob
.String
, rtype
);